export default {
	namespaced: true,
	state: {
		address: uni.getStorageSync('address') || null,
		token: uni.getStorageSync('token') || ''
	},
	mutations: {
		// 添加收货地址
		addAddress(state, address) {
			state.address = address
		},
		setToken(state, token) {
			state.token = token
		}
	},
	actions: {
		// 登录
		async login(ctx, obj) {
			const res = await uni.$http.post('/api/public/v1/users/wxlogin', obj)
			console.log(res.data.message.token);
			// 将token存入全局数据
			ctx.commit('setToken', res.data.message.token)
			// 将token存入本地数据
			uni.setStorageSync('token', res.data.message.token)
		}
	}
}
